Create new DGN file
To start with the OpenRoads designer, the first thing you need to do is create a Dgn file. The file has extension ".dgn". To create a new file, there must be an existing dgn file which serves as seed file.
The existing files which are used as seed can be found at location "C:\ProgramData\Bentley\OpenRoads Designer CE 10.11\Configuration\WorkSpaces\Training and Examples\Worksets\Training-Imperial\Standards\Seed\Seed2D - Imperial Training.dgn" if user has OpenRoads Designer installed.
bool CreateNewDGNFile()
{
Bentley.DgnPlatformNET.DgnFile newDGNFile;
//Path of existing file which is used as seed file for creating new file
String seedFilePath = "D:\\Dgn\\Seed2D-ImperialTraining.dgn";
//Create and Initialize session
Bentley.DgnPlatformNET.Host session = new Bentley.DgnPlatformNET.Host();
Bentley.DgnPlatformNET.DgnPlatformLib.Initialize(session, true);
//Create new document from seed file
Bentley.DgnPlatformNET.DgnDocument document = Bentley.DgnPlatformNET.DgnDocument.CreateForLocalFile(seedFilePath);
//Open the seed file for reading and copy the content from seed to new dgn
Bentley.DgnPlatformNET.DgnFileOwner owner = Bentley.DgnPlatformNET.DgnFile.Create(document, DgnFileOpenMode.ReadOnly);
newDGNFile = owner.DgnFile;
//load the newly created dgn for Read/Write
Bentley.DgnPlatformNET.StatusInt openForWriteStatus;
Bentley.DgnPlatformNET.DgnFileStatus fileStatus;
if (DgnFileStatus.Success != (fileStatus = newDGNFile.LoadDgnFile(out openForWriteStatus)))
return false;
//To save the new dgn file
newDGNFile.DoSaveTo("D:\\Dgn\\LatestDgn.dgn", DgnFileFormatType.Current);
return true;
}
Load the seed file in read mode to initialize the new dgn. Now load the newly created dgn in read/write mode and perform DoSaveTo() to save the newly created dgn file.